package com.mooco.dongba.sys.controller;

import com.mooco.dongba.sys.common.util.ShiroUtils;
import com.mooco.dongba.sys.pojo.SysUser;
import com.mooco.dongba.sys.pojo.SysUserMenu;
import com.mooco.dongba.sys.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class PageController {
    @Autowired
    private SysMenuService sysMenuService;

    /**
     * 首页：http://localhost/doIndexUI
     * @return
     */
    @RequestMapping("doIndexUI")
    public String doIndexUI(Model model) {
        //  后期要用Shiro框架处理
        SysUser user = ShiroUtils.getUser();
        model.addAttribute("username", user.getUsername());

        List<SysUserMenu> userMenus = sysMenuService.findUserMenusByUserId(user.getId());
        model.addAttribute("userMenus", userMenus);
        return "starter";
    }

    /** 加载分页组件 **/
    @RequestMapping("/doPageUI")
    public String doPageUI() {return "common/page";};

    @RequestMapping("{module}/{moduleUI}")
    public String doModuleUI(@PathVariable String moduleUI) {
        return "sys/" +moduleUI;
    }

    @RequestMapping("/doLoginUI")
    public String doLoginUI() {
        return "login";
    }
}
